﻿@namespace MudBlazor.UnitTests.TestComponents

<MudDataGrid ServerData="@(new Func<GridState<Item>, Task<GridData<Item>>>(ServerReload))" Sortable="true">
    <Columns>
        <Column T="Item" Field="@nameof(Item.A)" />
        <Column T="Item" Field="@nameof(Item.B)" />
    </Columns>
</MudDataGrid>

@code {
    public class Item
    {
        public int A { get; set; }
        public int B { get; set; }
    }
    private int _totalItems;

    /// <summary>
    /// Here we simulate getting the paged, filtered and ordered data from the server
    /// </summary>
    private async Task<GridData<Item>> ServerReload(GridState<Item> state)
    {
        IEnumerable<Item> data = new List<Item>() { new Item() { A=2, B=3 },
                                            new Item() { A=1, B=1 },
                                            new Item() { A=3, B=2 } };
        _totalItems = 3;

        data = data.OrderByDirection(state);

        return await Task.FromResult(new GridData<Item>() { TotalItems = _totalItems, Items = data });
    }
}
